(function($){
	$.fn.initial=function(){	
		searchBind();
		calTotal();
	}
	var searchBind=function(){
		$("#btn").on('click',$(this),function(){
			if ($('#name').val()=='') {
				alert("请输入查询作物名");
				return;
			}
			step1View();
			step2View();
			step3View();
			step4View();
			step5View();
			step6View();
			step7View();
			step8View();
			
			step1pView();
			step2pView();
			step3pView();
			step4pView();
			step5pView();
			step6pView();
			step7pView();
			step8pView();
			
			$('#zhongzhiyoumiao').val('');
			$('#linshigongtotal').val('');
			$('#jishugongtotal').val('');
			$('#jxtb').val('');
			$('#nongyao').val('');
			$('#huafei').val('');
		})
		
	}
	var selectBind=function(){
		$("#year-select").on('change',this,function(){
		step1View();
		step2View();
		step3View();
		step4View();
		step5View();
		step6View();
		step7View();
		step8View();
		})
	}
	
	var calTotal=function(){
		$('#calc').on('click',$(this),function(){
			var zzym=parseFloat($('#xiaohao1').val())*parseFloat($('#xiaohao1p').val());
			var linshigong=parseFloat($('#linshigong1').val())*parseFloat($('#linshigong1p').val())+parseFloat($('#linshigong2').val())*parseFloat($('#linshigong2p').val())+parseFloat($('#linshigong3').val())*parseFloat($('#linshigong3p').val())+
			parseFloat($('#linshigong4').val())*parseFloat($('#linshigong4p').val())+parseFloat($('#linshigong5').val())*parseFloat($('#linshigong5p').val())+
			parseFloat($('#linshigong6').val())*parseFloat($('#linshigong6p').val())+parseFloat($('#linshigong7').val())*parseFloat($('#linshigong7p').val())+parseFloat($('#linshigong8').val())*parseFloat($('#linshigong8p').val());
			var jishugong=parseFloat($('#jishugong1').val())*parseFloat($('#jishugong1p').val())+parseFloat($('#jishugong2').val())*parseFloat($('#jishugong2p').val())+parseFloat($('#jishugong3').val())*parseFloat($('#jishugong3p').val())+
			parseFloat($('#jishugong4').val())*parseFloat($('#jishugong4p').val())+parseFloat($('#jishugong8').val())*parseFloat($('#jishugong8p').val())+
			parseFloat($('#jishugong5').val())*parseFloat($('#jishugong5p').val())+parseFloat($('#jishugong6').val())*parseFloat($('#jishugong6p').val())+parseFloat($('#jishugong7').val())*parseFloat($('#jishugong7p').val());
			
			var jxtb=parseFloat($('#jiqi1').val())*parseFloat($('#jiqi1p').val())+parseFloat($('#jiqi2').val())*parseFloat($('#jiqi2p').val())+parseFloat($('#jiqi3').val())*parseFloat($('#jiqi3p').val());
			var nongyao=parseFloat($('#mcj').val())*parseFloat($('#mcjp').val())+parseFloat($('#ccj').val())*parseFloat($('#ccjp').val());
			var feiliao=	parseFloat($("#yjwjfh").val())*parseFloat($("#yjwjfhp").val())+parseFloat($("#elsgnd").val())*parseFloat($("#elsgndp").val())+parseFloat($("#ns").val())*parseFloat($("#nsp").val())+
			parseFloat($("#lsen").val())*parseFloat($("#lsenp").val())+parseFloat($("#lsj").val())*parseFloat($("#lsjp").val())+parseFloat($("#lf").val())*parseFloat($("#lfp").val())+parseFloat($("#yjf").val())*parseFloat($("#yjfp").val());
			$('#zhongzhiyoumiao').val(zzym);
			$('#linshigongtotal').val(linshigong);
			$('#jishugongtotal').val(jishugong);
			$('#jxtb').val(jxtb);
			$('#nongyao').val(nongyao);
			$('#huafei').val(feiliao);
		})
	}
	
	var step1View=function(){
		var data={"year":$("#year-select").val(),"name":$("#name").val()};
		$.ajax({
			url:"getStep1sByNY",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"];
					if (data!=null) {
						$("#linshigong1").val(data['linshigong']);
						$("#jishugong1").val(data['jishugong']);
						$("#xiaohao1").val(data['xiaohao']);
					}					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的种植数据");
					$("#linshigong1").val('');
					$("#jishugong1").val('');
					$("#xiaohao1").val('');
				}
			},
		})
	}
	
	var step2View=function(){
		var data={"year":$("#year-select").val(),"name":$("#name").val()};
		var body = $("#body2");
		body.html('');
		$.ajax({
			url:"getStep2sByNY",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"];
					if (data!=null) {
						$("#linshigong2").val(data['linshigong']);
						$("#jishugong2").val(data['jishugong']);
						$("#jiqi1").val(data['jiqi1']);
						$("#jiqi2").val(data['jiqi2']);
						$("#jiqi3").val(data['jiqi3']);
					}		
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的犁地数据");
					$("#linshigong2").val('');
					$("#jishugong2").val('');
					$("#jiqi1").val('');
					$("#jiqi2").val('');
					$("#jiqi3").val('');
				}
			},
		})
	}
	
	var step3View=function(){
		var data={"year":$("#year-select").val()};
		var body = $("#body3");
		body.html('');
		$.ajax({
			url:"getStep3sByNY",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"];
					if (data!=null) {
						$("#linshigong3").val(data['linshigong']);
						$("#jishugong3").val(data['jishugong']);
						$("#xiaohao3").val(data['xiaohao']);
					}
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的地膜数据");
					$("#linshigong3").val('');
					$("#jishugong3").val('');
					$("#xiaohao3").val('');
				}
			},
		})
	}
	
	var step4View=function(){
		var data={"year":$("#year-select").val(),"name":$("#name").val()};
		var body = $("#body4");
		body.html('');
		$.ajax({
			url:"getStep4sByNY",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"];
					if (data!=null) {
						$("#linshigong4").val(data['linshigong']);
						$("#jishugong4").val(data['jishugong']);
						$("#xiaohao4").val(data['xiaohao']);
					}
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的灌溉数据");
					$("#linshigong4").val('');
					$("#jishugong4").val('');
					$("#xiaohao4").val('');
				}
			},
		})
	}
	
	var step5View=function(){
		var data={"year":$("#year-select").val(),"name":$("#name").val()};
		var body = $("#body5");
		body.html('');
		$.ajax({
			url:"getStep5sByNY",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"];
					if (data!=null) {
						$("#linshigong5").val(data['linshigong']);
						$("#jishugong5").val(data['jishugong']);
						$("#yjwjfh").val(data['yjwjfh']);
						$("#elsgnd").val(data['elsgnd']);
						$("#ns").val(data['ns']);
						$("#lsen").val(data['lsen']);
						$("#lsj").val(data['lsj']);
						$("#lf").val(data['lf']);
						$("#yjf").val(data['yjf']);
					}			
			
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的施肥数据");
					$("#linshigong5").val('');
					$("#jishugong5").val('');
					$("#yjwjfh").val('');
					$("#elsgnd").val('');
					$("#ns").val('');
					$("#lsen").val('');
					$("#lsj").val('');
					$("#lf").val('');
					$("#yjf").val('');
				}
			},
		})
	}
	
	var step6View=function(){
		var data={"year":$("#year-select").val(),"name":$("#name").val()};
		var body = $("#body6");
		body.html('');
		$.ajax({
			url:"getStep6sByNY",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"];
					if (data!=null) {
						$("#linshigong6").val(data['linshigong']);
						$("#jishugong6").val(data['jishugong']);
						$("#ccj").val(data['ccj']);
						$("#mcj").val(data['mcj']);
					}			
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的喷药数据");
					$("#linshigong6").val('');
					$("#jishugong6").val('');
					$("#ccj").val('');
					$("#mcj").val('');
				}
			},
		})
	}
	
	var step7View=function(){
		var data={"year":$("#year-select").val(),"name":$("#name").val()};
		var body = $("#body7");
		body.html('');
		$.ajax({
			url:"getStep7sByNY",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"];
					if (data!=null) {
						$("#linshigong7").val(data['linshigong']);
						$("#jishugong7").val(data['jishugong']);
						$("#zhugan15").val(data['zhugan15']);
						$("#zhugan30").val(data['zhugan30']);
						$("#masheng").val(data['masheng']);
					}			
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的搭架数据");
					$("#linshigong7").val('');
					$("#jishugong7").val('');
					$("#zhugan15").val('');
					$("#zhugan30").val('');
					$("#masheng").val('');
				}
			},
		})
	}
	
	var step8View=function(){
		var data={"year":$("#year-select").val(),"name":$("#name").val()};
		var body = $("#body8");
		body.html('');
		$.ajax({
			url:"getStep8sByNY",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"];
					if (data!=null) {
						$("#linshigong8").val(data['linshigong']);
						$("#jishugong8").val(data['jishugong']);
					}								
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的采摘数据");
					$("#linshigong8").val('');
					$("#jishugong8").val('');
				}
			},
		})
	}
	
	var step1pView=function(){
	//	$('#name1p').val();
		$("#linshigong1p").val('');
		$("#jishugong1p").val('');
		$("#xiaohao1p").val('');
		
		var data={"year":$("#year-select").val()};
		$.ajax({
			url:"getps1",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
				//		$('#name1p').val(data['id']);
						$("#linshigong1p").val(data['linshigong']);
						$("#jishugong1p").val(data['jishugong']);
						$("#xiaohao1p").val(data['xiaohao']);
					}					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的种植数据");
			//		$('#name1p').val();
					$("#linshigong1p").val('');
					$("#jishugong1p").val('');
					$("#xiaohao1p").val('');
				}
			},
		})
	}
	
	var step2pView=function(){
		//$('#name2').val('');
		$("#linshigong2p").val('');
		$("#jishugong2p").val('');
		$("#jiqi1p").val('');
		$("#jiqi2p").val('');
		$("#jiqi3p").val('');
		var data={"year":$("#year-select").val()};
		var body = $("#body2");
		body.html('');
		$.ajax({
			url:"getps2",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
				//		$('#name2').val(data['id']);
						$("#linshigong2p").val(data['linshigong']);
						$("#jishugong2p").val(data['jishugong']);
						$("#jiqi1p").val(data['jiqi1']);
						$("#jiqi2p").val(data['jiqi2']);
						$("#jiqi3p").val(data['jiqi3']);
					}		
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的犁地数据");
					$('#name2').val('');
					$("#linshigong2p").val('');
					$("#jishugong2p").val('');
					$("#jiqi1p").val('');
					$("#jiqi2p").val('');
					$("#jiqi3p").val('');
				}
			},
		})
	}
	
	var step3pView=function(){
	//	$('#name3').val('');
		$("#linshigong3p").val('');
		$("#jishugong3p").val('');
		$("#xiaohao3p").val('');
		
		var data={"year":$("#year-select").val()};
		var body = $("#body3ByNY");
		body.html('');
		$.ajax({
			url:"getps3",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
			//			$('#name3').val(data['id']);
						$("#linshigong3p").val(data['linshigong']);
						$("#jishugong3p").val(data['jishugong']);
						$("#xiaohao3p").val(data['xiaohao']);
					}
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的地膜数据");
				//	$('#name3').val('');
					$("#linshigong3p").val('');
					$("#jishugong3p").val('');
					$("#xiaohao3p").val('');
				}
			},
		})
	}
	
	var step4pView=function(){
//		$('#name4').val('');
		$("#linshigong4p").val('');
		$("#jishugong4p").val('');
		$("#xiaohao4p").val('');
		
		var data={"year":$("#year-select").val()};
		var body = $("#body4ByNY");
		body.html('');
		$.ajax({
			url:"getps4",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
				//		$('#name4').val(data['id']);
						$("#linshigong4p").val(data['linshigong']);
						$("#jishugong4p").val(data['jishugong']);
						$("#xiaohao4p").val(data['xiaohao']);
					}
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的灌溉数据");
				//	$('#name4').val('');
					$("#linshigong4p").val('');
					$("#jishugong4p").val('');
					$("#xiaohao4p").val('');
				}
			},
		})
	}
	
	var step5pView=function(){
		//$('#name5').val('');
		$("#linshigong5p").val('');
		$("#jishugong5p").val('');
		$("#yjwjfhp").val('');
		$("#elsgndp").val('');
		$("#nsp").val('');
		$("#lsenp").val('');
		$("#lsjp").val('');
		$("#lfp").val('');
		$("#yjfp").val('');
		
		var data={"year":$("#year-select").val()};
		var body = $("#body5ByNY");
		body.html('');
		$.ajax({
			url:"getps5",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
			//			$('#name5').val(data['id']);
						$("#linshigong5p").val(data['linshigong']);
						$("#jishugong5p").val(data['jishugong']);
						$("#yjwjfhp").val(data['yjwjfh']);
						$("#elsgndp").val(data['elsgnd']);
						$("#nsp").val(data['ns']);
						$("#lsenp").val(data['lsen']);
						$("#lsjp").val(data['lsj']);
						$("#lfp").val(data['lf']);
						$("#yjfp").val(data['yjf']);
					}			
			
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的施肥数据");
				//	$('#name5').val('');
					$("#linshigong5p").val('');
					$("#jishugong5p").val('');
					$("#yjwjfhp").val('');
					$("#elsgndp").val('');
					$("#nsp").val('');
					$("#lsenp").val('');
					$("#lsjp").val('');
					$("#lfp").val('');
					$("#yjfp").val('');
				}
			},
		})
	}
	
	var step6pView=function(){
	//	$('#name6').val('');
		$("#linshigong6p").val('');
		$("#jishugong6p").val('');
		$("#ccjp").val('');
		$("#mcjp").val('');
		
		var data={"year":$("#year-select").val()};
		var body = $("#body6");
		body.html('');
		$.ajax({
			url:"getps6",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
			//			$('#name6').val(data['id']);
						$("#linshigong6p").val(data['linshigong']);
						$("#jishugong6p").val(data['jishugong']);
						$("#ccjp").val(data['ccj']);
						$("#mcjp").val(data['mcj']);
					}			
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的喷药数据");
				//	$('#name6').val('');
					$("#linshigong6p").val('');
					$("#jishugong6p").val('');
					$("#ccjp").val('');
					$("#mcjp").val('');
				}
			},
		})
	}
	
	var step7pView=function(){
	//	$('#name7').val('');
		$("#linshigong7p").val('');
		$("#jishugong7p").val('');
		$("#zhugan15p").val('');
		$("#zhugan30p").val('');
		$("#mashengp").val('');
		var data={"year":$("#year-select").val()};
		var body = $("#body7");
		body.html('');
		$.ajax({
			url:"getps7",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
		//				$('#name7').val(data['id']);
						$("#linshigong7p").val(data['linshigong']);
						$("#jishugong7p").val(data['jishugong']);
						$("#zhugan15p").val(data['zhugan15']);
						$("#zhugan30p").val(data['zhugan30']);
						$("#mashengp").val(data['masheng']);
					}			
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的搭架数据");
			//		$('#name7').val('');
					$("#linshigong7p").val('');
					$("#jishugong7p").val('');
					$("#zhugan15p").val('');
					$("#zhugan30p").val('');
					$("#mashengp").val('');
				}
			},
		})
	}
	
	var step8pView=function(){
//		$('#name8').val('');
		$("#linshigong8p").val('');
		$("#jishugong8p").val('');
		var data={"year":$("#year-select").val()};
		var body = $("#body8");
		body.html('');
		$.ajax({
			url:"getps8",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
			//			$('#name8').val(data['id']);
						$("#linshigong8p").val(data['linshigong']);
						$("#jishugong8p").val(data['jishugong']);
					}								
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的采摘数据");
				//	$('#name8').val('');
					$("#linshigong8p").val('');
					$("#jishugong8p").val('');
				}
			},
		})
	}
})(jQuery)